package com.sike.netty.im.client.handler;

import cn.hutool.core.date.DateUtil;
import com.sike.netty.im.common.command.OneChatResponseCommand;
import com.sike.netty.im.common.enums.ResponseStatusEnum;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;


/**
 * 单聊响应 handler
 *
 * @author chenssy
 * @date 2023/09/16
 */
public class OneChatResponseHandler extends SimpleChannelInboundHandler<OneChatResponseCommand> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, OneChatResponseCommand msg) throws Exception {
        // 输出收到的消息
        if (ResponseStatusEnum.SUCCESS.getCode().equals(msg.getRetCode())) {
            System.out.println("[" + DateUtil.now() + "]：" + msg.getFromUserName() + " >>> " + msg.getMessage());
        } else {
            System.out.println("[" + DateUtil.now() + "]：>>> " + msg.getRetMessage());
        }
    }
}
